<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\CoUser;
use App\Models\CoSchool;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;

class CoUserController extends AdminController
{
    protected $title ='会员管理';
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new CoUser(), function (Grid $grid) {
            $grid->id->sortable();
            $grid->nickname;
            $grid->mobile;
            $grid->avatar->image('',80,80);
            $grid->gender->display(function ($sex){
                if($sex ==1){
                    return '男';
                }else{
                    return '女';
                }
            });
            $grid->column('type','状态')->switch();
            $grid->login_time;
            $grid->regist_date;
            $grid->created_at;
            $grid->updated_at->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
            $grid->disableDeleteButton();
            $grid->disableEditButton();
            $grid->disableCreateButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CoUser(), function (Show $show) {
            $show->id;
            $show->nickname;
            $show->mobile;
            $show->avatar->image();
            $show->gender->as(function ($v){
                if($v==1){
                    return '男';
                }else{
                    return '女';
                }
            });
            $show->login_time;


            $show->regist_date;
            $show->created_at;
            $show->updated_at;
            $show->disableDeleteButton();
            $show->disableEditButton();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CoUser(), function (Form $form) {
            $form->display('id');
            $form->text('avatar');
            $form->text('gender');
            $form->text('login_time');
            $form->text('mobile');
            $form->text('nickname');
            $form->text('regist_date');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
